
package online.xuping.thousandsOfWorlds.common.snowflake;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Mybatis集成配置
 * 1.集成雪花算法拦截器
 *
 * @author dongyinggang
 * @date 2022/10/20 18:07
 * @copyright 2022 山东新北洋信息技术股份有限公司. All rights reserved
 */

@Configuration
public class MybatisConfig {

    @Autowired
    private SnowflakeIdWorker snowflakeIdWorker;

    /**
     * 集成雪花算法拦截器
     *
     * @return {@link PrimaryKeyInterceptor }
     * @author dongyinggang
     * @date 2022/10/21 8:10
     **/
    @Bean
    public PrimaryKeyInterceptor primaryKeyInterceptor() {
        PrimaryKeyInterceptor primaryKeyInterceptor = new PrimaryKeyInterceptor();
        primaryKeyInterceptor.setPrimaryKey("id");
        primaryKeyInterceptor.setSnowflakeIdWorker(snowflakeIdWorker);
        return primaryKeyInterceptor;
    }
}
